#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int findTargetSumWays(vector<int> &nums, int target)
    {
        int sum = accumulate(nums.begin(), nums.end(), 0);
        if (abs(target) > sum)
            return 0;
        if ((sum + target) % 2 != 0)
            return 0;
        int bag_size = (sum + target) / 2;
        vector<int> dp(bag_size + 1, 0);
        dp[0] = 1;
        for (int i = 0; i < (int)nums.size(); i++)
        {
            for (int j = bag_size; j >= nums[i]; j--)
            {
                dp[j] += dp[j - nums[i]];
            }
        }
        return dp[bag_size];
    }
};

int main()
{
    vector<int> nums{1, 1, 1, 1, 1};
    Solution sol;
    cout << sol.findTargetSumWays(nums, 3) << endl;
    return 0;
}